package the.world.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import the.world.bean.Game;
import the.world.bean.HotArticles;
import the.world.bean.Navigation;
import the.world.mapper.GuideMapper;
import the.world.service.GuiService;

import java.util.ArrayList;
import java.util.List;

@Service
public class GuiServiceImpl implements GuiService {
    @Autowired
    private GuideMapper guiMapper;
    @Override
    public List<Game> responseTitleData(String name) {
        return guiMapper.findByName(name);
    }

    @Override
    public List<HotArticles> findByGameName(String name) {
        List<HotArticles> result = new ArrayList<HotArticles>();
        List<Game> games = responseTitleData(name);
        if (!games.isEmpty()){
            for (Game game : games) {
                List<HotArticles> hotArticles = guiMapper.findById(game.getHotStrategiesId());
                result.addAll(hotArticles);
            }
        }
        return result;
    }

    @Override
    public List<Navigation> getNavigation() {
        return guiMapper.responseNavigation();
    }

    @Override
    public List<Navigation> getNavigationPath(String name) {
        return guiMapper.responseNavigationByName(name);
    }
}
